package com.atguigu.dao.impl;

import java.util.List;

import com.atguigu.beans.User;
import com.atguigu.dao.BasicDao;
import com.atguigu.dao.UserDao;
import com.sun.corba.se.spi.servicecontext.UEInfoServiceContext;

public class UserDaoImpl implements UserDao {

	// 创建BasicDao对象
	BasicDao basicDao = new BasicDao();

	@Override
	public User checkUsernameAndPassword(String username, String password) {
		// 写sql语句
		String sql = "select id,username,password,email from users where username = ? and password = ?";
		// 调用BasicDao中获取一个对象的方法
		User bean = basicDao.getBean(User.class, sql, username, password);
		return bean;
	}

	@Override
	public boolean checkUsername(String username) {
		// 写sql语句
		String sql = "select id,username,password,email from users where username = ?";
		// 调用BasicDao中获取一个对象的方法
		User bean = basicDao.getBean(User.class, sql, username);
		return bean != null;
	}

	@Override
	public void saveUser(String username, String password, String email) {
		// 写sql语句
		String sql = "insert into users(username,password,email) values(?,?,?)";
		// 调用BasicDao中通用的增删改的方法
		basicDao.update(sql, username, password, email);
	}

	@Override
	public List<User> getUsers() {
		// 写sql语句
		String sql = "select id,username,password,email from users";
		// 调用BasicDao中获取List的方法
		List<User> beanList = basicDao.getBeanList(User.class, sql);
		return beanList;
	}

}
